#include "datatunnel.h"

#include <QDebug>

class DataTunnelPrivate
{
public:
    QString type;
    QString name;
    QList<double> data;
    QWidget* graph = nullptr;
};

DataTunnel::DataTunnel(QObject *parent) : QObject(parent)
{
    d_ptr = new DataTunnelPrivate;
}

DataTunnel::~DataTunnel()
{
    delete d_ptr;
}

DataTunnel* DataTunnel::instance()
{
    static DataTunnel _inst;
    return &_inst;
}

void DataTunnel::setType(const QString& type)
{
    d_ptr->type = type;
}

QString DataTunnel::type() const
{
    return d_ptr->type;
}

void DataTunnel::setName(const QString& name)
{
    d_ptr->name = name;
}

QString DataTunnel::name() const
{
    return d_ptr->name;
}

void DataTunnel::setData(const QList<double>& data)
{
    d_ptr->data = data;
}

void DataTunnel::addData(double data)
{
    d_ptr->data.append(data);
}

QList<double> DataTunnel::data() const
{
    return d_ptr->data;
}

void DataTunnel::startDrag()
{
    emit beginDragging();
}

bool DataTunnel::isEmpty() const
{
    return d_ptr->data.isEmpty();
}

void DataTunnel::reset()
{
    qDebug() << __FUNCTION__;
    d_ptr->type.clear();
    d_ptr->data.clear();
    d_ptr->graph = nullptr;
}

void DataTunnel::attach(QWidget* graph)
{
    if (d_ptr->graph != graph)
        d_ptr->graph = graph;
}

QWidget* DataTunnel::attachedWidget() const
{
    return d_ptr->graph;
}
